//
//  ArtistCell_second.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/8/24.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "ArtistCell_second.h"
#import "XiangQingViewController.h"
@implementation ArtistCell_second

- (void)awakeFromNib
{
    [super awakeFromNib];
    _imageV.layer.cornerRadius = 15;
    _imageV.layer.masksToBounds = YES;
    
    _attentionBtn.layer.cornerRadius = 15;
    _attentionBtn.layer.masksToBounds = YES;
    _attentionBtn.layer.borderColor = [UIColor c1Color].CGColor;
    _attentionBtn.layer.borderWidth = 1;
    
    _photo1.backgroundColor = [UIColor c2Color];
    _photo2.backgroundColor = [UIColor c2Color];
    _photo3.backgroundColor = [UIColor c2Color];
    _photo1.hidden =  YES;
    _photo2.hidden =  YES;
    _photo3.hidden =  YES;
}
- (IBAction)attentionBtnClick:(id)sender
{
//    _attentionBtn.selected = !_attentionBtn.selected;
    self.attentionBtnBlock(_attentionBtn);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:_dic[@"image"]] placeholderImage:[UIImage imageNamed:@"place_head_Icon"]];
    _nameL.text = _dic[@"nike"];
//    _upTitleL.text = [NSString stringWithFormat:@"新上传%@件作品", _dic[@"productNum"]];
    _upTitleL.text = [NSString stringWithFormat:@"%@ %@", _dic[@"productNum"],NSLocalizedString(@"New uploads", nil)];
    _attentionBtn.selected = [_dic[@"attentionState"] isEqualToString:@"0"] ? YES : NO;
    NSArray *arr = _dic[@"productBeanList"];

    _photo1.hidden = arr.count >= 1 ? NO : YES;
    _photo2.hidden = arr.count >= 2 ? NO : YES;
    _photo3.hidden = arr.count >= 3 ? NO : YES;
    
    _photo1.userInteractionEnabled = YES;
    _photo2.userInteractionEnabled = YES;
    _photo3.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPhoto:)];
    [_photo1 addGestureRecognizer:tap];
    [_photo2 addGestureRecognizer:tap];
    [_photo3 addGestureRecognizer:tap];
    
    if (arr.count >= 1)
    {
        _photo1.hidden = NO;
        [_photo1 sd_setImageWithURL:[NSURL URLWithString:arr[0][@"image"]]];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPhoto:)];
        [_photo1 addGestureRecognizer:tap];
    }
    if (arr.count >= 2)
    {
        _photo2.hidden = NO;
        [_photo2 sd_setImageWithURL:[NSURL URLWithString:arr[1][@"image"]]];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPhoto:)];
        [_photo2 addGestureRecognizer:tap];
    }
    if (arr.count >= 3)
    {
        _photo3.hidden = NO;
        [_photo3 sd_setImageWithURL:[NSURL URLWithString:arr[2][@"image"]]];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPhoto:)];
        [_photo3 addGestureRecognizer:tap];
    }
}

- (void)clickPhoto:(UITapGestureRecognizer *)tap
{
    UIView *view = tap.view;
    NSArray *arr = _dic[@"productBeanList"];
    if ([view isEqual:_photo1] && !_photo1.hidden)
    {
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = arr[0][@"id"];
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
        return;
    }
    if ([view isEqual:_photo2] && !_photo2.hidden)
    {
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = arr[1][@"id"];
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
        return;
    }
     if ([view isEqual:_photo3] && !_photo3.hidden)
    {
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = arr[2][@"id"];
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
        return;
    }
}

@end
